//
//  OtherViewController.m
//  CycleControlFunction
//
//  Created by 苹果笔记本 on 2020/11/19.
//  Copyright © 2020 cycle. All rights reserved.
//

#import "OtherViewController.h"
#import "NSString+CycleStrTool.h"
@interface OtherViewController ()

@property(nonatomic,strong)UIView *containerView;


@property(nonatomic,strong)UILabel *label2;


@end

@implementation OtherViewController


- (UILabel *)label2 {
    if (!_label2) {
        _label2 = [[UILabel alloc]initWithFrame:self.containerView.bounds];
        _label2.textColor = [UIColor redColor];
        _label2.font = [UIFont systemFontOfSize:14];
        _label2.textAlignment = NSTextAlignmentLeft;
        _label2.text = @"222";
        _label2.numberOfLines = 0;
    }
    return _label2;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"副文本";
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.label2];
    
    NSString *contentStr = @"哈哈哈哈哈，北京欢迎你，哈哈哈哈，来到这里了，，哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈，嘻嘻嘻休息嘻嘻嘻嘻,哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈，嘻嘻嘻休息嘻嘻嘻嘻哈哈哈哈哈，北京欢迎你，哈哈哈哈，来到这里了，，哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈，嘻嘻嘻休息嘻嘻嘻嘻,哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈，嘻嘻嘻休息嘻嘻嘻嘻哈哈哈哈哈，北京欢迎你，哈哈哈哈，来到这里了，，哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈，嘻嘻嘻休息嘻嘻嘻嘻,哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈，嘻嘻嘻休息嘻嘻嘻嘻";
    
    
    
    self.label2.attributedText = [NSString cycle_contentStr:contentStr lineSpace:4 wordSpace:1 font:[UIFont systemFontOfSize:14]];
    
    
    CGFloat textHeight = [self cycle1_getSpaceLabelHeightwithSpeace:4 withFont:[UIFont systemFontOfSize:14] withWidth:[UIScreen mainScreen].bounds.size.width-40 wordSpace:1 contentStr:contentStr];
    self.label2.frame = CGRectMake(20, 100, [UIScreen mainScreen].bounds.size.width-40, textHeight);
    
    
    
}

-(CGFloat)cycle1_getSpaceLabelHeightwithSpeace:(CGFloat)lineSpeace withFont:(UIFont*)font withWidth:(CGFloat)width wordSpace:(CGFloat)wordSpace contentStr:(NSString *)contentStr{
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    //    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    /** 行高 */
    paraStyle.lineSpacing = lineSpeace;
    // NSKernAttributeName字体间距
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@(wordSpace)
                          };
    CGSize size = [contentStr boundingRectWithSize:CGSizeMake(width,MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    return size.height;
}
@end
